

import { GetModelService, LogUtil, ModelTool, Util, ViewTool } from "ibiz-core";
import { IPSAppCodeList, IPSAppDataEntity, IPSAppDERedirectView, IPSAppDEView, IPSAppUILogicRefView, IPSAppUIOpenDataLogic, IPSAppView, IPSAppViewLogic, IPSAppViewRef, IPSDEGridColumn, IPSDEGridEditItem, IPSDEGridFieldColumn, IPSEditor, IPSNavigateContext, IPSNavigateParam } from "@ibiz/dynamic-model-api";

/**
 * 审核状态表格列插件插件类
 *
 * @export
 * @class ShztGridColumu
 * @extends {Vue}
 */
export class ShztGridColumu {


    public renderColumn(h:any, column:any, scope:any, actionContext:any){
      const codeList: IPSAppCodeList | null = column.getPSAppCodeList();      
      const dataItemName = column.dataItemName;
      const name = column.name.toLowerCase();
      const row = scope.row;
      return  <div class="column-link" style="display:flex;align-items:center">
                <codelist
                  value={row[dataItemName]}
                  codeList={codeList}
                >
                </codelist>
                {row.status == "30" ? 
                <el-tooltip class="item" effect="light" content={row.rejectreason} placement="right">
                  <img class="tip-pic" src="./assets/img/grid-column/tips.svg" style="cursor:pointer;margin-left:5px;"></img> 
                </el-tooltip>                
                : null}
      </div>
    }

    /**
     * 绘制数据列
     *
     * @param {any} column 表格列实例
     * @memberof AppGridBase
     */
    public renderGridColumn(h:any,column: IPSDEGridColumn,actionContext:any) {
        const { name, codeName, enableRowEdit, width, caption, widthUnit, align, enableSort } = column;
        const editItem: IPSDEGridEditItem = ModelTool.getGridItemByCodeName(
            codeName,
            actionContext.controlInstance,
        ) as IPSDEGridEditItem;
        const sysImage = column.getPSSysImage();
        let renderParams: any = {
            label: actionContext.$tl(column.getCapPSLanguageRes()?.lanResTag, caption),
            prop: name,
            align: align ? align.toLowerCase() : 'center',
            sortable: !actionContext.controlInstance.noSort && enableSort ? 'custom' : false,
        };
        if (widthUnit && widthUnit != 'STAR') {
            renderParams['width'] = width;
        } else {
            renderParams['min-width'] = width;
        }
        return h('el-table-column', {
            props: renderParams,
            scopedSlots: {
                default: (scope: any) => {
                    return this.renderColumn(h, column, scope, actionContext);
                },
                header: () => {
                    actionContext.allColumnsInstance; // 别删，触发表格头刷新用
                    return (
                        <span class='column-header'>
                            {sysImage ? <i class={sysImage?.cssClass} style='margin-right: 4px;'></i> : null}
                            {actionContext.$tl(column.getCapPSLanguageRes()?.lanResTag, caption)}
                        </span>
                    );
                },
            },
        });
    }

    /**
     * 绘制插件
     *
     * @param h createElement对象
     * @param modelJson 表单项实例
     * @param actionContext 表单vue对象
     * @param event 事件源
     */
    public renderCtrlItem(h: any, modelJson: IPSDEGridColumn, actionContext: any, event: any) {
        return this.renderGridColumn(h,modelJson,actionContext)
    }  


}

